package main.entities;


import main.states.Play;
import main.tileMap.Map;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tiled.TiledMap;


public abstract class Entity {
	/**entity coordinates*/
	protected double x, y;
	/**entity's width and height*/
	protected double width, height;
	/**entity's move speed*/
	protected double moveSpeed;
	protected double aceleration;
	
	protected double health;
	/**entity's tile position in tile set*/
	protected int[] id;
	/**Image for rendering entity*/
	protected Image image;
	
	private Rectangle me;
	private Rectangle him;
	protected double maxSpeed;
	protected Map map; 
	
	public Entity(String s, double x, double y, double width, double height){
		try {
			image = new Image(s);
		} catch (SlickException e) {
			System.out.println("Error cargando entity imagen");
		}
		this.x =x;
		this.y = y;

		this.height=height;
		this.width = width;
		
		moveSpeed = 0;
		maxSpeed = 1.8;
		aceleration =0.2;
		
		health = 100;
		me = new Rectangle((int)x,(int)y,(int)width,(int)height);
		
	}
	
	public void move(double delta){
		x += moveSpeed;
		y += moveSpeed;
	}
	
	
	public void render(Graphics g){
		g.drawImage(image,(int)(x),(int)(y),null);
	}
	
	public boolean colidesWith(Entity entity){
		him.setBounds((int)entity.x,(int)entity.y, (int)entity.width,(int)entity.height);

		return me.intersects(him);
		
	}
	public double getX(){
		return x;
	}
	public double getY(){
		return y;
	}
	public double getWidth(){
		return width;
	}
	public double getheigth(){
		return height;
	}
	
	public abstract void collideWith(Entity entity);

	public void update(GameContainer gc, StateBasedGame sbg, int g) {
		// TODO Auto-generated method stub
		
	}

	public  void keyPressed(int key, char c){}
		
	

	public  void keyReleased(int key, char c) {}

	public void addMap(Map map) {
		this.map =map;
		
	}

	
	protected boolean tryToMove(float tx, float ty) {
        float newx = (float) (tx);
        float newy = (float) (ty);
        // checks the blocked array for collision
        if (map.blocked((newx), (newy))) {
            //can't move if blocked is true at the given location
            return false;
        }else{
           //allows the move
             return true;
        }       
  }
	


	
	
}
